package org.dromara.apartment.controller;

import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.apartment.domain.bo.ApartmentInfoBo;
import org.dromara.apartment.domain.bo.RoomInfoBo;
import org.dromara.apartment.domain.vo.ApartmentInfoVo;
import org.dromara.apartment.domain.vo.RoomInfoVo;
import org.dromara.apartment.service.IApartmentInfoService;
import org.dromara.apartment.service.IRoomInfoService;
import org.dromara.common.area.core.Area;
import org.dromara.common.area.core.utils.AreaUtils;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.vo.CityVo;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 不校验登录 Controller
 * @author CKJ
 * @description: 不校验登录
 * @date 2025/7/7 16:23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ignore-login")
public class IgnoreLoginController {
    private final IApartmentInfoService apartmentInfoService;
    private final IRoomInfoService roomInfoService;

    /**
     * 根据城市ID获取区
     *
     * @param cityId 城市ID
     */
    @GetMapping("/apartment/getDistrictByCityId/{cityId}")
    public R<List<Area>> getApartmentAppInfo(@NotNull(message = "城市ID不能为空")
                                    @PathVariable("cityId") Integer cityId) {
        return R.ok(AreaUtils.getDistrictsByCityId(cityId));
    }

    /**
     * 查询已开通城市
     * @return
     */
    @GetMapping("/apartment/getOpenCity")
    public R<List<CityVo>> getApartmentOpenCity() {
        return R.ok(apartmentInfoService.getOpenCity());
    }

    /**
     * 查询公寓列表
     */
    @GetMapping("/apartment/app-page")
    public TableDataInfo<ApartmentInfoVo> getApartmentAppPage(ApartmentInfoBo bo, PageQuery pageQuery) {
        return apartmentInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取公寓管理详细信息
     *
     * @param id 主键
     */
    @GetMapping("/apartment/app-info/{id}")
    public R<ApartmentInfoVo> getApartmentAppInfo(@NotNull(message = "主键不能为空")
                                         @PathVariable("id") Long id) {
        return R.ok(apartmentInfoService.queryAppInfoById(id));
    }

    /**
     * 查询最近7个超高性价比房间
     * @return
     */
    @GetMapping("/room/cost-effective")
    public R<List<RoomInfoVo>> getRoomCostEffectiveRooms() {
        return R.ok(roomInfoService.getCostEffectiveRooms());
    }

    /**
     * 查询5个推荐好房
     * @return
     */
    @GetMapping("/room/recommend")
    public R<List<RoomInfoVo>> getRoomRecommendRooms() {
        return R.ok(roomInfoService.getRecommendRooms());
    }

    /**
     * 查询房间信息列表
     */
    @GetMapping("/room/app-page")
    public TableDataInfo<RoomInfoVo> getRoomAppPage(RoomInfoBo bo, PageQuery pageQuery) {
        return roomInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取房间信息详细信息
     *
     * @param id 主键
     */
    @GetMapping("/room/app-info/{id}")
    public R<RoomInfoVo> getRoomAppInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable("id") Long id) {
        return R.ok(roomInfoService.queryById(id));
    }
}
